<?php
/**
 * Created by PhpStorm.
 * User: tom_xia
 * Date: 2018/5/30
 * Time: 15:52
 * 审核列表
 */
require_once __DIR__."/login_filter.php";
use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\model\UserMaterial;

$page = isset($_GET["page"]) ? intval($_GET["page"]) : 1;
$page = $page > 0 ? $page : 1;
$size = 5;
//1.获取有视频提交的日期
$dateKey = REDIS_PREFIX."dy_date_list_{$Auth["union_id"]}_{$type}";
$redis = SysResource::getRedis();
$date = $redis->get($dateKey);
if($date){
    $date = json_decode($date,true);
}else{
    $db = SysResource::getDB(false);
    $where = "user_uuid = '{$Auth["user_uuid"]}' and is_save = 1";
    $query = $db->query("select `date` from (select DATE_FORMAT(add_time,'%Y-%m-%d') as `date` from qmjs_user_material where {$where} ) as a GROUP BY `date` ORDER BY `date` desc  ");
    $result = $query->all();
    $date = array_column($result,"date");
    $redis->setEx($dateKey,10,json_encode($date));
}
if(isset($date[($page-1)*$size])){
    $startIndex = ($page-1)*$size;
    $db = SysResource::getDB(false);
    $userMaterialModel = new UserMaterial($db);
    //最终生成的数据
    $data = [];

    for($start = 0;$start<$size;$start++){
        $currentDate = isset($date[$startIndex+$start]) ? $date[$startIndex+$start] : NULL;
        if(empty($currentDate)){
            break;
        }
        $condition = array();
        $condition["eq"]["user_uuid"] = $Auth["user_uuid"];

        $condition["eq"]["add_time>="] = $currentDate;
        $condition["eq"]["add_time<"] = date("Y-m-d",strtotime($currentDate)+86400);
        $condition["order"]["add_time"] = "desc";
        $condition["eq-filter"]["is_save"] = 1;
        $condition["select"] = "user_material_uuid,video_name,music_video_url as video_url,status";
        $result = $userMaterialModel->getList($condition,false);

        $tempData = ["audit_data"=>[],"date"=>$currentDate];
        $tempData["audit_data"] = $result;
        $data[] = $tempData;
    }
}else{
    $data = [];
}
Response::output(0,"ok",$data);

